﻿using Cap.PcWebSite.Services.Dtos;
using DotNetCore.CAP;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;

namespace Cap.PcWebSite.Controllers
{

    /// <summary>
    /// PC端用户控制器
    /// </summary>
    [Route("PcUser")]
    [ApiController]
    public class PcUserController:AbpController
    {
        public ICapPublisher capPublisher { get; set; }

        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        [HttpPost]
        public string RegisterUser(UserInfoDto userInfo)
        {
            //发布事件userRegister，携带数据userInfo
            //事件发送后存储到消息队列，可以使用rabbitmq，kafka
            capPublisher.Publish< UserInfoDto>("userRegister", userInfo);

            return $"注册成功..:UserName={userInfo.UserName}";
        }

        /// <summary>
        /// 注册用户(测试消费失败)
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        [HttpPost("Register")]
        public string RegisterUserFail(UserInfoDto userInfo)
        {
            //发布事件userRegister，携带数据userInfo
            //事件发送后存储到消息队列，可以使用rabbitmq，kafka
            capPublisher.Publish<UserInfoDto>("userRegisterFail", userInfo);
            return $"注册成功..:UserName={userInfo.UserName}";
        }


    }
}
